package com.yxkj.syh.app.huarong.activities.orders.pay_list;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.syh.app.basic.base.BaseResponse;
import com.syh.app.basic.base.view_model.BaseViewModel;
import com.syh.app.basic.utils.Tooast;
import com.syh.app.basic.utils.net.ApiObserver;
import com.trello.rxlifecycle2.android.FragmentEvent;
import com.yxkj.syh.app.huarong.bean.PagesRequest;
import com.yxkj.syh.app.huarong.bean.PayOrderListResponse;
import com.yxkj.syh.app.huarong.data_center.model.OrderModel;

import java.util.HashMap;
import java.util.Map;

/**
 * 创建者：SYH
 * 时间：2020/6/10 15:29
 * 编辑者：SYH、
 * 标签：
 * 补充说明：
 */
public class PayOrdersVM extends BaseViewModel<FragmentEvent> {

    public PayOrdersVM(@NonNull Application application) {
        super(application);
    }

    public MutableLiveData<PayOrderListResponse.Data> mldPayOrderListResponse = new MutableLiveData<>();
    public MutableLiveData<Boolean> mldReceiveMoney = new MutableLiveData<>();

    public void payOrderList(PagesRequest pagesRequest){
        OrderModel.getOrderModel().payOrderList(pagesRequest, mLifecycleProvider.bindToLifecycle(), new ApiObserver<PayOrderListResponse>() {
            @Override
            public void onSuccess(PayOrderListResponse payOrderListResponse) {
                mldPayOrderListResponse.setValue(payOrderListResponse.getData());
            }

            @Override
            public void onFailed(int code, String msg) {
                Tooast.warning(msg);
                mldPayOrderListResponse.setValue(null);
            }
        });
    }

    public  void payOrderReceiveMoney(String id){
        Map<String,Object> pMap = new HashMap<>();
        pMap.put("expensesId",id);

        showLoading("payOrderReceiveMoney");
        OrderModel.getOrderModel().payOrderReceiveMoney(pMap, mLifecycleProvider.bindToLifecycle(), new ApiObserver<BaseResponse>() {
            @Override
            public void onSuccess(BaseResponse response) {
                hideLoading("payOrderReceiveMoney");
                mldReceiveMoney.setValue(true);
                Tooast.success(response.getMessage());
            }

            @Override
            public void onFailed(int code, String msg) {
                hideLoading("payOrderReceiveMoney");
                mldReceiveMoney.setValue(false);
            }
        });
    }

}
